<template>
  <div>
    <el-form ref="form"
             :model="detailInfo"
             :rules="rules"
             label-width="85px"
             size="small">
      <el-row>
        <el-col :span="6">
          <el-form-item label="组别"
                        prop="group">
            <el-select v-model="detailInfo.territory"
                       placeholder="请选择"
                       :disabled="mode != 0">
              <el-option v-for="item in options.territory"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="计划月份"
                        prop="monthplan">
            <el-col :span="24">
              <el-date-picker v-model="detailInfo.planTime"
                              type="month"
                              style='width:100%'
                              :disabled="mode != 0"
                              placeholder="选择月份">
              </el-date-picker>
            </el-col>
          </el-form-item>
        </el-col>
        <el-col :span="6"
                v-if="mode == 2">
          <el-form-item label="自签目标"
                        prop="sinceSigning">
            <el-input v-model="detailInfo.sinceSigning"
                      :disabled="mode != 0"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6"
                v-if="mode == 2">
          <el-form-item label="协签目标"
                        prop="agreementSigned">
            <el-input v-model="detailInfo.agreementSigned"
                      :disabled="mode != 0"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="mode == 1">
        <el-col :span="6">
          <el-form-item label="小组主跟"
                        prop="responsibilityTarget">
            <el-input v-model="detailInfo.responsibilityTarget"
                      :disabled="mode != 0"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="运营主跟"
                        prop="operationTarget">
            <el-input v-model="detailInfo.operationTarget"
                      :disabled="mode != 0"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="大区主跟"
                        prop="areaTarget">
            <el-input v-model="detailInfo.areaTarget"
                      :disabled="mode != 0"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 表格  -->
    <el-table :data="tableData"
              border
              show-summary
              stripe>
      <el-table-column prop="contractId"
                       label="合同号"
                       align="center"
                       width="110"></el-table-column>
      <el-table-column prop="contractName"
                       label="项目名称"
                       header-align="center">
        <template slot-scope="props">
          <el-popover placement="bottom"
                      trigger="hover"
                      :content="props.row.contractName">
            <span slot="reference"
                  class="table-overflow-hidden">{{props.row.contractName}}</span>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column prop="primaryTerritory"
                       label="主跟进组"
                       align="center"
                       width="90"></el-table-column>
      <el-table-column prop="signType"
                       label="签订类型"
                       sortable
                       align="center"
                       width="100"></el-table-column>
      <el-table-column prop="estimatedAmount"
                       label="预估金额"
                       sortable
                       align="center"
                       width="90"></el-table-column>
      <el-table-column prop="projectMaturity"
                       label="成熟度"
                       sortable
                       align="center"
                       width="80"></el-table-column>
      <el-table-column prop="contractDate"
                       label="签订计划"
                       sortable
                       align="center"
                       width="100"></el-table-column>
      <el-table-column prop="tm"
                       label="计划月份"
                       sortable
                       align="center"
                       width="100"></el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination layout="total, sizes, prev, pager, next, jumper"
                   :total="pagging.total"
                   :current-page="pagging.currentPage"
                   :page-sizes="pagging.sizes"
                   @size-change="sizeChange"
                   @current-change="pageChange">
    </el-pagination>
  </div>
</template>

<script>
import { getPlanInfo } from '@/api/maintenance'
import { mapGetters } from 'vuex'
import Moment from 'moment'
export default {
  props: {
    mode: {
      type: Number
    },
    detailInfo: {
      type: Object
    }
  },
  data() {
    return {
      tableData: [],
      // 分页属性
      pagging: {
        total: 0,
        currentPage: 1,
        pageSize: 10,
        sizes: [10, 30, 50, 100]
      },
      // 选项数据
      options: {
        territory: [{
          value: null,
          label: null
        }]
      },
      // 表单验证规则
      rules: {
        territory: [
          { required: true, message: '请选择分组', trigger: 'change' }
        ],
        planTime: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        sinceSigning: [
          { required: true, message: '请输入自签金额', trigger: 'blur' }
        ],
        agreementSigned: [
          { required: true, message: '请输入协签金额', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'appEnum'
    ])
  },
  mounted() {
    this.initEnum()
    this.getTableData()
  },
  methods: {
    // 请求月份计划项目数据
    getTableData() {
      getPlanInfo({
        territory: this.detailInfo.territory,
        advancingState: '是',
        planMonth: Moment(this.detailInfo.planTime).format('YYYY-MM'),
        pageSize: this.pagging.pageSize,
        pageIndex: this.pagging.currentPage
      }).then(res => {
        if (res.data.success) {
          const result = res.data.data
          this.tableData = result.data
          this.pagging.total = result.totalCount
          this.pagging.currentPage = result.pageIndex
          this.pagging.pageSize = result.pageSize
          this.loading = false
        }
      })
    },
    // 初始化下拉菜单
    initEnum() {
      this.options.territory = this.appEnum.territory
    },
    // 每页显示条数变更新
    sizeChange(size) {
      this.pagging.pageSize = size
      this.getTableData()
    },
    // 跳转到页面
    pageChange(curPage) {
      this.pagging.currentPage = curPage
      this.getTableData()
    }
  },
  watch: {
    detailInfo() {
      this.pagging.currentPage = 1
      this.getTableData()
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
